using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Linq;
using System.Web.Mvc;
using InfoTech.Core.Service;
using InfoTech.LanTranh.MucVu.Bussiness;

namespace InfoTech.LanTranh.MucVu.Service
{
    public class TONGIAOService : BaseService
    {
        public static bool Check_Insert_TONGIAO(TONGIAO tongiao)
        {
            bool result = true;
            DataContext dataContext = CreateDataContext();
            result &=
                dataContext.GetTable<TONGIAO>().FirstOrDefault(
                    c => c.TENTONGIAO.ToUpper() == tongiao.TENTONGIAO.ToUpper()) == null;
            return result;
        }

        public static bool Check_Update_TONGIAO(TONGIAO tongiao)
        {
            bool result = true;
            DataContext dataContext = CreateDataContext();
            result &=
                dataContext.GetTable<TONGIAO>().FirstOrDefault(
                    c => c.TENTONGIAO.ToUpper() == tongiao.TENTONGIAO.ToUpper() && c.MATONGIAO != tongiao.MATONGIAO) == null;
            return result;
        }

        public static bool Check_Delete_TONGIAO(string[] strings)
        {
            bool result = true;
            DataContext dataContext = CreateDataContext();
            result &=
                dataContext.GetTable<SOHONNHAN>().FirstOrDefault(
                    c => strings.Contains(c.MATONGIAO + "")) == null;
            return result;
        }

        public static void Delete(TONGIAO tongiao)
        {
        }

        public static IEnumerable<SelectListItem> Get_List()
        {
            List<SelectListItem> list = new List<SelectListItem>();
            list.AddRange(InfoTech.Core.Data.Receiver.TypeObject<TONGIAO>.SelectMany().OrderBy(c=>c.PRIORITY).Select(
                    c => new SelectListItem() { Text = c.TENTONGIAO, Value = c.MATONGIAO + "" }));
            return list;
        }
    }
}
